home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 002 / ew.arc / EW.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1987-12-10  |  29.7 KB  |  1,048 lines

  1.  
  2. {                            EASY-WRITE  v. 1.0
  3.                              ~~~~~~~~~~~~~~~~~~
  4.  
  5.  
  6.  Note: This editor is donated to the "public domain".  You can make illimited
  7.  ~~~~
  8.        copies of it.
  9.  
  10.        However, if you modify it to better suit your tastes, I would appreciate
  11.  
  12.        that you mention it before distributing the modified version.
  13.  
  14.        Feel free to send me your comments, good or bad.
  15.  
  16.        This program has been written with Turbo Pascal v. 3.01a.
  17.  
  18.        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  19.  
  20.        Guy Lachance,
  21.  
  22.        [71460,3407].
  23.  
  24.        last revision : 87/12/10
  25.  
  26.        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  27. }
  28.  
  29.  
  30. PROGRAM EasyWrite (input,output);
  31.  
  32. {$R+}
  33.  
  34. CONST                           (* max number of lines of the document      *)
  35.   maxline=2000;                 (* you can change it, but it will slow down *)
  36.                                 (* some commands, namely Ctrl-N and Ctrl-L  *)
  37. TYPE
  38. string80=string[80];
  39. linepointer=^lineOftext;
  40. Lineoftext=string80;
  41.  
  42. VAR
  43. worksheet:array[1..maxline] of LinePointer;
  44. WaitForRetrace:boolean;
  45. BaseOfScreen:Integer;
  46. x,y,z:integer;
  47. blankString:string80;
  48. bkstrindex:integer;
  49. wcActive,loadflag,firstime:boolean;
  50. wcnoli:integer;
  51. edmode:(ist,overwrite);
  52.  
  53. (* EgaInstalled, GetVideoMode and FastwriteNA are from Brian Foley
  54.    [76317,3247] Thanks Brian !   *)
  55.  
  56. FUNCTION EgaInstalled : Boolean;
  57.   {-Test for presence of the EGA. I have little idea how this works, but
  58.     it does.}
  59. BEGIN
  60. Inline(
  61.   $B8/$00/$12      {      MOV AX,$1200}
  62.   /$BB/$10/$00     {      MOV BX,$10}
  63.   /$B9/$FF/$FF     {      MOV CX,$FFFF}
  64.   /$CD/$10         {      INT $10}
  65.   /$31/$C0         {      XOR AX,AX}
  66.   /$81/$F9/$FF/$FF {      CMP CX,$FFFF}
  67.   /$74/$01         {      JE DONE}
  68.   /$40             {      INC AX}
  69.   /$88/$46/$04     {DONE: MOV [BP+$04],AL}
  70. );
  71. END;
  72.  
  73. PROCEDURE GetVideoMode;
  74.   {-Video mode of 7 indicates mono display; all other modes are for color
  75.     displays. This routine MUST be called before any of the screen writing
  76.     routines are used!}
  77. VAR
  78.      Mode : Integer;
  79. BEGIN
  80.      Inline(
  81.        $B4/$0F        {MOV AH,$F}
  82.        /$CD/$10       {INT $10}
  83.        /$30/$E4       {XOR AH,AH}
  84.        /$89/$46/<Mode {MOV [BP+<Mode],AX}
  85.      );
  86.      IF Mode = 7 THEN BaseOfScreen := $B000  { Mono }
  87.                  ELSE BaseOfScreen := $B800; { Color }
  88.      WaitForRetrace := (BaseOfScreen = $B800) And Not EgaInstalled;
  89.      { If WaitForRetrace is True, you may want to allow the user to decide
  90.        whether to forego snow prevention in favor of faster screen updates.
  91.        *VERY IMPORTANT*  WaitForRetrace MUST be false if BaseOfScreen = $B000. }
  92. END;
  93.  
  94. PROCEDURE FastWriteNA( St : String80; Row, Col : Byte );
  95.   {-Same as FastWrite, but no attribute byte paramater. String appears
  96.     in whatever attribute(s) was/were there to begin with.}
  97. BEGIN
  98. Inline(
  99.   $8C/$DB                {         MOV BX,DS                ;Save DS in BX}
  100.   /$31/$C0               {         XOR AX,AX}
  101.   /$88/$C1               {         MOV CL,AL}
  102.   /$8A/$AE/>Row          {         MOV CH,[BP+>Row]}
  103.   /$FE/$CD               {         DEC CH}
  104.   /$D1/$E9               {         SHR CX,1}
  105.   /$89/$CF               {         MOV DI,CX}
  106.   /$D1/$EF               {         SHR DI,1}
  107.   /$D1/$EF               {         SHR DI,1}
  108.   /$01/$CF               {         ADD DI,CX}
  109.   /$8B/$8E/>Col          {         MOV CX,[BP+>Col]}
  110.   /$49                   {         DEC CX}
  111.   /$D1/$E1               {         SHL CX,1}
  112.   /$01/$CF               {         ADD DI,CX}
  113.   /$8E/$06/>BaseOfScreen {         MOV ES,[>BaseOfScreen]}
  114.   /$8A/$0E/>WaitForRetrace{        MOV CL,[>WaitForRetrace]}
  115.   /$8C/$D2               {         MOV DX,SS}
  116.   /$8E/$DA               {         MOV DS,DX}
  117.   /$8D/$B6/>St           {         LEA SI,[BP+>St]}
  118.   /$FC                   {         CLD}
  119.   /$AC                   {         LODSB}
  120.   /$91                   {         XCHG AX,CX}
  121.   /$E3/$26               {         JCXZ Exit}
  122.   /$D0/$D8               {         RCR AL,1}
  123.   /$73/$1E               {         JNC NoWait}
  124.   /$BA/$DA/$03           {         MOV DX,$03DA}
  125.   /$AC                   {Next:    LODSB}
  126.   /$88/$C4               {         MOV AH,AL                ;Store char in AH}
  127.   /$FA                   {         CLI}
  128.   /$EC                   {WaitNoH: IN AL,DX}
  129.   /$A8/$08               {         TEST AL,8}
  130.   /$75/$09               {         JNZ Store}
  131.   /$D0/$D8               {         RCR AL,1}
  132.   /$72/$F7               {         JC WaitNoH}
  133.   /$EC                   {WaitH:   IN AL,DX}
  134.   /$D0/$D8               {         RCR AL,1}
  135.   /$73/$FB               {         JNC WaitH}
  136.   /$88/$E0               {Store:   MOV AL,AH                ;Move char back to AL...}
  137.   /$AA                   {         STOSB                    ; and then to screen}
  138.   /$FB                   {         STI}
  139.   /$47                   {         INC DI}
  140.   /$E2/$E7               {         LOOP Next}
  141.   /$EB/$04               {         JMP SHORT Exit}
  142.   /$A4                   {NoWait:  MOVSB                    ;Move character to screen}
  143.   /$47                   {         INC DI                   ;Skip attribute bytes}
  144.   /$E2/$FC               {         LOOP NoWait}
  145.   /$8E/$DB               {Exit:    MOV DS,BX                ;Restore DS from BX}
  146. );
  147. END;
  148.  
  149.  
  150. PROCEDURE ChangeCursor(CursorType:integer);
  151.  
  152. (*
  153. CursorType of 1 : change cursor to normal
  154. "    "     "  2 : change cursor to a box
  155. *)
  156.  
  157. var
  158.   start,stop : byte;
  159.   Regs: RECORD
  160.           CASE integer of
  161.             0: (ax,bx,cx,dx,bp,si,di,ds,es,flags : integer);
  162.             1: (al,ah,bl,bh,cl,ch,dl,dh : byte)
  163.         END;
  164.  
  165. begin      (* of procedure ChangeCursor *)
  166.  
  167.   CASE cursorType of
  168.     1: begin
  169.          start:=11;
  170.          stop:=12;
  171.        end;
  172.     2: begin
  173.          start:=2;
  174.          stop:=12;
  175.        end;
  176.   END;
  177. WITH Regs DO
  178.   begin
  179.     ax:=$0100;
  180.     ch:=Start;
  181.     cl:=Stop;
  182.     Intr($10,Regs);
  183.   end;
  184.  
  185. end;   (* of procedure changeCursor *)
  186.  
  187.  
  188. PROCEDURE DLWC;   (* procedure to Determine the Length of the Working Copy *)
  189.   var             (* "wcnoli" becomes the number of the last line *)
  190.     i:integer;    (* if it is 0 then it means that the Working Copy is empty *)
  191.   begin
  192.     i:=maxline+1;
  193.     REPEAT
  194.     i:=i-1;
  195.     UNTIL ((length(worksheet[i]^)<>0) or (i=1));
  196.     wcnoli:=i;
  197.     if ((wcnoli=1) and (length(worksheet[1]^)=0)) then wcnoli:=0;
  198.   end;
  199.  
  200.  
  201. PROCEDURE initialize;
  202. var
  203.   k,i:integer;
  204.   p:linepointer;
  205. begin
  206.   x:=1; y:=1; z:=1;
  207.   wcnoli:=0;
  208.   wcActive:=false;
  209.   loadflag:=false;
  210.   for k:=1 to maxline do
  211.     begin
  212.       if firstime then
  213.         begin
  214.           new(p);
  215.           Worksheet[k]:=p;
  216.         end;
  217.       Worksheet[k]^:=blankString;
  218.       Worksheet[k]^[0]:=chr(0);
  219.     end;
  220. end;   (* of initialize *)
  221.  
  222. PROCEDURE Load;
  223.  
  224.   type
  225.     string20=string[20];
  226.     string137=string[137];
  227.  
  228.   var
  229.     index,j:integer;
  230.     Textfile:text;
  231.     filename:string20;
  232.     scratch:string137;
  233.     cf,choice:char;
  234.  
  235.   begin       (* of procedure load  *)
  236.     clrscr;
  237.     gotoxy(35,25);
  238.     lowvideo;
  239.     write('LOAD FILE');
  240.     normvideo;
  241.     gotoxy(5,5);
  242.     write('Enter filename : ');
  243.     readln(filename);
  244.     (* filename:='b:\'+filename;  *)       { remove the comments if you   }
  245.     assign(Textfile,filename);             { want easy-write to load from }
  246.     {$I-}                                  { drive b:                     }
  247.     reset(Textfile);
  248.     {$I+}
  249.     If IOresult <> 0 then
  250.       begin
  251.          writeln; writeln;
  252.          gotoxy(5,wherey);
  253.          writeln('PROBLEM... Cannot find ',filename);
  254.          write(chr(7));
  255.          writeln;
  256.          writeln;
  257.          gotoxy(5,wherey);
  258.          write('Press  <──┘  to continue');
  259.          readln;
  260.  
  261.        end
  262.     ELSE
  263.       BEGIN
  264.       choice:='n';
  265.       if wcActive then
  266.       begin
  267.       writeln;
  268.       gotoxy(5,wherey);
  269.       writeln('WARNING !! You are about to overwrite the Working Copy...');
  270.       writeln;
  271.       gotoxy(5,wherey);
  272.       write('Do you want to continue ? (y/n) : ');
  273.       readln(choice);
  274.       end;
  275.       if (not wcActive) or  (choice in ['y','Y']) then    (* proceed *)
  276.       begin
  277.       x:=1; y:=1; z:=1;
  278.       index:=1;
  279.       writeln;
  280.       gotoxy(5,wherey);
  281.       write('Loading ',filename,'... Please Wait.');
  282.       if ((wcActive) or (loadflag)) then initialize;
  283.       WHILE ((NOT EOF(Textfile)) and (index <= maxline)) DO
  284.         begin
  285.           readln(Textfile,scratch);
  286.           worksheet[index]^:=scratch;
  287.           index:=index+1;
  288.         end;
  289.       DLWC;
  290.       loadflag:=true;
  291.       close(textfile);
  292.       if index > maxline then
  293.         begin
  294.           writeln; writeln;
  295.           gotoxy(5,wherey);
  296.           writeln('WARNING : The file is too big. It has NOT been loaded entirely.');
  297.           writeln;
  298.           gotoxy(5,wherey);
  299.           write('Press  <──┘  to continue');
  300.           readln;
  301.         end;
  302.       end;
  303.       END;
  304.  
  305.   end;                 (*   of the procedure load       *)
  306.  
  307. PROCEDURE Save;
  308.   label
  309.     saveError;
  310.   type
  311.     string20=string[20];
  312.   var
  313.     Textfile:text;
  314.     filename:string20;
  315.     i:integer;
  316.  
  317.   begin                     (* of procedure save *)
  318.     clrscr;
  319.     lowvideo;
  320.     gotoxy(31,25);
  321.     write('SAVE WORKING COPY');
  322.     normvideo;
  323.     IF wcnoli <> 0 then
  324.       begin                 (* save *)
  325.         gotoxy(5,5);
  326.         write('Enter filename : ');
  327.         readln(filename);
  328.         (* filename:='b:\'+filename;  *)            { remove the comments if }
  329.         assign(Textfile,filename);                  { you want easy-write to }
  330.         {$I-}                                       { save to drive b:       }
  331.         rewrite(Textfile);
  332.         {$I+}
  333.         if IOresult <> 0 then goto saveError;
  334.         gotoxy(5,7);
  335.         write('Saving ',filename,'... Please wait.');
  336.         for i:=1 to wcnoli do
  337.           writeln(Textfile,worksheet[i]^);
  338.         close(Textfile);
  339.         wcActive:=false;
  340.         loadflag:=true;
  341.       end
  342.     ELSE
  343.       begin
  344.         gotoxy(5,5);
  345.         write('ERROR : The Working Copy is empty.');
  346.         gotoxy(5,7);
  347.         write('Press  <──┘  to continue');
  348.         readln;
  349.       end;
  350.  
  351.   if 1=2 then
  352.   saveError:
  353.     begin
  354.       gotoxy(5,7);
  355.       write('ERROR : You have to give a name.');
  356.       gotoxy(5,9);
  357.       write('Press  <──┘  to continue');
  358.       readln;
  359.     end;
  360.  
  361.   end;       (* of procedure save *)
  362.  
  363. PROCEDURE Print;
  364.   var
  365.     printerSelection:char;
  366.     style:char;
  367.     lineCounter:integer;
  368.     doubleSpace:char;
  369.     i,j:integer;
  370.     top,bottom,pl:integer;
  371.  
  372.   function PrinterOK:boolean;   (* test if printer is ready *)
  373.   var
  374.     Regs:RECORD
  375.            AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS:integer;
  376.          END;
  377.   begin
  378.     Regs.DX:=$0000;
  379.     Regs.AX:=$0100;
  380.     Intr($17,Regs);
  381.     PrinterOK:=(NOT(Odd(Regs.AX Shr 11))) AND (NOT(Odd(Regs.AX Shr 13)));
  382.   end;
  383.  
  384.   begin      (* procedure print *)
  385.     clrscr;
  386.     lowvideo;
  387.     gotoxy(31,25);
  388.     write('PRINT WORKING COPY');
  389.     normvideo;
  390.     if wcnoli <> 0 then
  391.     begin
  392.     gotoxy(5,5);
  393.     write('1'); lowvideo; write(') Star SG-10            '); normvideo;
  394.     write('2'); lowvideo; write(') IBM Pro Printer            '); normvideo;
  395.     write('3'); lowvideo; write(') CANCEL PRINTING  '); normvideo;
  396.     gotoxy(5,9);
  397.     write('Enter selection : ');
  398.     readln(printerSelection);
  399.     if not(printerSelection in ['1'..'3']) then
  400.       repeat
  401.         gotoxy(5,9);
  402.         write('Enter selection : ');
  403.         clreol;
  404.         readln(printerSelection);
  405.       until printerSelection in ['1'..'3'];
  406.     if printerSelection <> '3' then
  407.       begin
  408.         if not printerok then
  409.           repeat
  410.           gotoxy(5,11);
  411.           write('PROBLEM : The printer is not ready.');
  412.           gotoxy(5,13);
  413.           write('Make it READY and then press  <──┘  to continue');
  414.           readln;
  415.           until printerok;
  416.         gotoxy(5,11); clreol; gotoxy(5,13); clreol;
  417.         gotoxy(5,11);
  418.         write('Do you want to print in NLQ ?  (y/n) : ');
  419.         readln(style);
  420.         if style in ['y','Y'] then
  421.         case printerselection of
  422.           '1' : write(lst,chr(27),chr(52));
  423.           '2' : write(lst,chr(27),chr(71));
  424.           end;
  425.         gotoxy(5,13);
  426.         write('Do you want to print in double-space ?  (y/n) : ');
  427.         readln(doubleSpace);
  428.         gotoxy(5,15);
  429.         write('   Enter top margin : ');
  430.         readln(top);
  431.         gotoxy(5,17);
  432.         write('Enter bottom margin : ');
  433.         readln(bottom);
  434.         gotoxy(5,19);
  435.         write('  Enter page length : ');
  436.         readln(pl);
  437.         gotoxy(5,21);
  438.         write('Printing...Please wait.');
  439.         for j:=1 to top do write(lst,chr(10));
  440.         lineCounter:=0;
  441.         for i:=1 to wcnoli do
  442.           begin
  443.             writeln(lst,worksheet[i]^);
  444.             lineCounter:=lineCounter+1;
  445.             if lineCounter=(pl-top-bottom) then
  446.               begin
  447.                 write(lst,chr(12));
  448.                 for j:=1 to top  do write(lst,chr(10));
  449.                 lineCounter:=0;
  450.               end;
  451.             if doublespace in ['y','Y'] then
  452.                begin
  453.                  write(lst,chr(10));
  454.                  lineCounter:=lineCounter+1;
  455.                end;
  456.             if lineCounter=(pl-top-bottom) then
  457.               begin
  458.                 write(lst,chr(12));
  459.                 for j:=1 to top  do write(lst,chr(10));
  460.                 lineCounter:=0;
  461.               end;
  462.           end;
  463.           case printerselection of
  464.          '1': write(lst,chr(27),chr(53));
  465.          '2': write(lst,chr(27),chr(72));
  466.          end;
  467.          write(lst,chr(12));
  468.          delay(5000);
  469.       end;
  470.     end
  471.     else
  472.       begin
  473.         gotoxy(5,5);
  474.         write('ERROR : The working copy is empty.');
  475.         gotoxy(5,7);
  476.         write('Press  <──┘  to continue');
  477.         readln;
  478.       end;
  479.  
  480.  
  481.   end;      (* procedure print *)
  482.  
  483. PROCEDURE Erase;
  484.   var
  485.     choice:char;
  486.   begin
  487.     clrscr;
  488.     lowvideo;
  489.     gotoxy(31,25);
  490.     write('ERASE WORKING COPY');
  491.     normvideo;
  492.     choice:='n';
  493.     if wcActive then
  494.     begin
  495.     gotoxy(5,5);
  496.     write('WARNING !!   You are about to erase the working copy.');
  497.     gotoxy(5,7);
  498.     write('Your changes have NOT been saved.');
  499.     gotoxy(5,9);
  500.     write('Do you want to continue ? (y/n) : ');
  501.     readln(choice);
  502.     end;
  503.     if (not wcActive) or  (choice in ['y','Y']) then   (* proceed *)
  504.       begin
  505.         if wcActive then  gotoxy(5,11)
  506.         else gotoxy(5,5);
  507.         write('Erasing the WORKING COPY. Please wait... ');
  508.         initialize;
  509.       end;
  510.   end;            (* of procedure erase *)
  511.  
  512.  
  513. PROCEDURE EDIT;
  514. var
  515.  
  516. ch:char;
  517. i,j,k,m:integer;
  518. escape,updatey:boolean;
  519. u,d,e,t:integer;
  520. aiv:integer;
  521.  
  522. procedure refresh(start:integer);
  523.   var
  524.     b:byte;
  525.     q:integer;
  526.   begin
  527.     if edmode=ist then
  528.     fastwriteNA('Esc : Main menu            Mode : Insert           Line : 1       Column : 1',1,1)
  529.     else
  530.     fastwriteNA('Esc : Main menu            Mode : Overwrite        Line : 1       Column : 1',1,1);
  531.     fastwriteNA('────────────────────────────────────────────────────────────────────────────────',2,1);
  532.     fastwriteNA('┴┴┴┴┼┴┴┴┴1┴┴┴┴┼┴┴┴┴2┴┴┴┴┼┴┴┴┴3┴┴┴┴┼┴┴┴┴4┴┴┴┴┼┴┴┴┴5┴┴┴┴┼┴┴┴┴6┴┴┴┴┼┴┴┴┴7┴┴┴┴┼┴┴┴┴',25,1);
  533.     q:=start;
  534.     window(1,1,80,25);
  535.     gotoxy(59,1);
  536.     write('        ');
  537.     gotoxy(59,1);
  538.     write(z);
  539.     gotoxy(76,1);
  540.     write('  ');
  541.     gotoxy(76,1);
  542.     write(x);
  543.     window(1,3,80,24);
  544.     for b:=3 to 24 do
  545.       begin
  546.         fastwriteNA('                                                                                 ',b,1);
  547.         fastwriteNA(worksheet[q]^,b,1);
  548.         q:=q+1;
  549.       end;
  550.   end;       (* of procedure refresh *)
  551.  
  552. begin       (* of procedure EDIT *)
  553.   clrscr;
  554.   if edmode=ist then changeCursor(2);
  555.   window(1,3,80,24);
  556.   refresh(z-y+1);
  557.   gotoxy(x,y);
  558.   REPEAT
  559.   ch:=chr(1);
  560.   escape:=false;
  561.   if keypressed then
  562.     begin
  563.       read(kbd,ch);
  564.       if (ch=#27) and keypressed then
  565.         begin
  566.           escape:=true;
  567.           read(kbd,ch);
  568.         end;
  569.     end;
  570.   if escape then         (* escape codes *)
  571.    begin
  572.     case ord(ch) of
  573.        75:if x>1 then                (* left arrow key *)
  574.             begin
  575.               gotoxy(wherex-1,wherey);
  576.               x:=x-1;
  577.               window(1,1,80,25);
  578.               gotoxy(76,1);
  579.               write('  ');
  580.               gotoxy(76,1);
  581.               write(x);
  582.               window(1,3,80,24);
  583.               gotoxy(x,y);
  584.             end;
  585.        77:if ((x<=80) and (not((x=80) and (z=maxline)))) then
  586.             begin                            (* right arrow key *)
  587.               updatey:=false;
  588.               gotoxy(wherex+1,wherey);
  589.               x:=x+1;
  590.               if ((x>80) and (z < maxline))  then
  591.                   begin
  592.                     if wherey=22 then
  593.                       begin
  594.                         z:=z+1;  x:=1;
  595.                         refresh(z-21);
  596.                         gotoxy(x,22);
  597.                         updatey:=true;
  598.                       end
  599.                     else
  600.                       begin
  601.                         x:=1; y:=y+1; z:=z+1;
  602.                         updatey:=true;
  603.                       end;
  604.                  end;
  605.               window(1,1,80,25);
  606.               gotoxy(76,1);
  607.               write('  ');
  608.               gotoxy(76,1);
  609.               write(x);
  610.               if updatey then
  611.                 begin
  612.                   gotoxy(59,1);
  613.                   write('        ');
  614.                   gotoxy(59,1);
  615.                   write(z);
  616.                 end;
  617.               window(1,3,80,24);
  618.               gotoxy(x,y);
  619.             end;
  620.        72:if y>1 then                (* up arrow key *)
  621.  
  622.             begin
  623.               gotoxy(wherex,wherey-1);
  624.               y:=y-1;   z:=z-1;
  625.               window(1,1,80,25);
  626.               gotoxy(59,1);
  627.               write('        ');
  628.               gotoxy(59,1);
  629.               write(z);
  630.               window(1,3,80,24);
  631.               gotoxy(x,y);
  632.             end
  633.  
  634.             else
  635.  
  636.             if ((wherey=1) and (z<>1)) then
  637.              begin
  638.                z:=z-1;
  639.                refresh(z);
  640.                gotoxy(x,1);
  641.              end;
  642.  
  643.        80:if z<maxline then          (* down arrow key *)
  644.             if wherey=22 then
  645.               begin
  646.                 z:=z+1;
  647.                 refresh(z-21);
  648.                 gotoxy(x,22);
  649.               end
  650.             else
  651.             begin
  652.               gotoxy(wherex,wherey+1);
  653.               y:=y+1;
  654.               z:=z+1;
  655.               window(1,1,80,25);
  656.               gotoxy(59,1);
  657.               write('        ');
  658.               gotoxy(59,1);
  659.               write(z);
  660.               window(1,3,80,24);
  661.               gotoxy(x,y);
  662.             end;
  663.        71:if x>1 then            (* home key *)
  664.          begin
  665.            gotoxy(1,wherey);
  666.            x:=1;
  667.            window(1,1,80,25);
  668.            gotoxy(76,1);
  669.            write('  ');
  670.            gotoxy(76,1);
  671.            write(x);
  672.            window(1,3,80,24);
  673.            gotoxy(x,y);
  674.          end;
  675.                                           (* end key *)
  676.        79:  begin
  677.               if length(worksheet[z]^) < 80 then
  678.                   begin
  679.                     gotoxy((length(worksheet[z]^)+1),wherey);
  680.                     x:=(length(worksheet[z]^))+1;
  681.                   end
  682.                else
  683.                  begin
  684.                     gotoxy((length(worksheet[z]^)),wherey);
  685.                     x:=(length(worksheet[z]^));
  686.                   end;
  687.               window(1,1,80,25);
  688.               gotoxy(76,1);
  689.               write('  ');
  690.               gotoxy(76,1);
  691.               write(x);
  692.               window(1,3,80,24);
  693.               gotoxy(x,y);
  694.             end;
  695.  
  696.        82: begin                       (* insert/overwrite toggle *)
  697.              if (edmode=ist) then
  698.                begin
  699.                  edmode:=overwrite;
  700.                  changeCursor(1);
  701.                end
  702.              else
  703.                begin
  704.                  edmode:=ist;
  705.                  changeCursor(2);
  706.                end;
  707.              refresh(z-y+1);
  708.              gotoxy(x,y);
  709.            end;
  710.  
  711.       132: begin                  (* Ctrl-PgUp : to top of working copy *)
  712.              x:=1;   y:=1;   z:=1;
  713.              refresh(1);
  714.              gotoxy(1,1);
  715.            end;
  716.  
  717.       118: begin                  (* Ctrl-PgDn : to end of working copy *)
  718.              if wcnoli > 0 then z:=wcnoli else z:=1;
  719.              if wcnoli > 0 then
  720.              m:=length(worksheet[wcnoli]^) else m:=0;
  721.              if m=80 then x:=m else x:=m+1;
  722.              if wcnoli < 23 then
  723.                begin
  724.                  if wcnoli > 0 then y:=wcnoli else y:=1;
  725.                  refresh(1);
  726.                end
  727.              else
  728.                begin
  729.                  y:=22;
  730.                  refresh(z-21);
  731.                end;
  732.              gotoxy(x,y);
  733.            end;
  734.  
  735.        83: if x <= length(worksheet[z]^) then    (* del key *)
  736.              begin
  737.                wcActive:=true;
  738.                delete(worksheet[z]^,x,1);
  739.                refresh(z-y+1);
  740.                gotoxy(x,y);
  741.              end;
  742.  
  743.        end;      (* of the case statement *)
  744.  
  745.   end
  746.   else                   (* non escape codes *)
  747.   if not (ch in [chr(32)..chr(255)]) then
  748.     begin
  749.       case ord(ch) of
  750.         13: if z<maxline then               (* return key *)
  751.             case edmode of
  752.     OVERWRITE:
  753.             begin                           (* with auto-indent *)
  754.             j:=0;
  755.             if length(worksheet[z]^) = 0 then
  756.               aiv:=1
  757.               else
  758.                 begin
  759.                   repeat
  760.                   j:=j+1;
  761.                   until ((worksheet[z]^[j] <> ' ') or (j=80));
  762.                   aiv:=j;
  763.                 end;
  764.             if wherey=22 then
  765.               begin
  766.                 z:=z+1;   x:=aiv;
  767.                 refresh(z-21);
  768.                 gotoxy(x,22);
  769.               end
  770.               else
  771.               begin
  772.                 x:=aiv;
  773.                 y:=y+1;  z:=z+1;
  774.                 window(1,1,80,25);
  775.                 gotoxy(59,1);
  776.                 write('        ');
  777.                 gotoxy(59,1);
  778.                 write(y);
  779.                 gotoxy(76,1);
  780.                 write('  ');
  781.                 gotoxy(76,1);
  782.                 write(x);
  783.                 window(1,3,80,24);
  784.                 gotoxy(x,y);
  785.               end;
  786.             end;
  787.  
  788.     IST:    begin
  789.                wcActive:=true;
  790.                if length(worksheet[z]^) = 0 then
  791.                aiv:=1
  792.                else
  793.                begin
  794.                j:=0;
  795.                repeat
  796.                j:=j+1;
  797.                until ((worksheet[z]^[j] <> ' ') or (j=80));
  798.                aiv:=j;
  799.                end;
  800.                x:=aiv;   z:=z+1;
  801.                if wherey < 22 then y:=y+1;
  802.                for k:=wcnoli downto z do
  803.                  begin
  804.                    worksheet[k+1]^:=blankString;
  805.                    worksheet[k+1]^:=worksheet[k]^;
  806.                  end;
  807.                worksheet[z]^:=blankString;
  808.                worksheet[z]^[0]:=chr(0);
  809.                wcnoli:=wcnoli+1;
  810.                refresh(z-y+1);
  811.                gotoxy(x,y);
  812.             end;
  813.          end;   (* of the case statement *)
  814.  
  815.         12: if (wcnoli > 0) and (z <= wcnoli) then
  816.             begin               (* Ctrl-L : delete a line *)
  817.               wcActive:=true;
  818.               for k:=(z+1) to wcnoli do
  819.                 begin
  820.                   worksheet[k-1]^:=blankString;
  821.                   worksheet[k-1]^:=worksheet[k]^;
  822.                 end;
  823.               worksheet[wcnoli]^:=blankString;
  824.               worksheet[wcnoli]^[0]:=chr(0);
  825.               wcnoli:=wcnoli-1;
  826.               refresh(z-y+1);
  827.               gotoxy(x,y);
  828.             end;
  829.  
  830.          14: if wcnoli < maxline then
  831.               begin                         (* Ctrl-N : insert a blank line *)
  832.                 wcActive:=true;
  833.                 for k:=wcnoli downto z do
  834.                   begin
  835.                     worksheet[k+1]^:=blankString;
  836.                     worksheet[k+1]^:=worksheet[k]^;
  837.                   end;
  838.                 worksheet[z]^:=blankString;
  839.                 worksheet[z]^[0]:=chr(0);
  840.                 wcnoli:=wcnoli+1;
  841.                 refresh(z-y+1);
  842.                 gotoxy(x,y);
  843.               end;
  844.  
  845.          8: if x>1 then         (* backspace key *)
  846.               begin
  847.                 wcActive:=true;
  848.                 gotoxy(wherex-1,wherey);
  849.                 x:=x-1;
  850.                 delete(worksheet[z]^,x,1);
  851.                 refresh(z-y+1);
  852.                 gotoxy(x,y);
  853.               end;
  854.         end;
  855.     end
  856.   else                    (* write a char to the screen and in the array *)
  857.     CASE edmode of
  858.  
  859.     OVERWRITE:
  860.  
  861.     begin
  862.      write(ch);   wcActive:=true;
  863.      x:=x+1;
  864.      if ((x>80) and (z < maxline)) then
  865.      begin
  866.      if wherey=22 then
  867.          begin
  868.            z:=z+1;  x:=1;
  869.            refresh(z-21);
  870.            gotoxy(1,22);
  871.          end
  872.         else
  873.         begin
  874.           x:=1; y:=y+1; z:=z+1;
  875.         end;
  876.      end;
  877.      if ((x > 80) and (z=maxline)) then x:=1;    (* if reached the end of the working copy *)
  878.      window(1,1,80,25);
  879.      gotoxy(76,1);
  880.      write('  ');
  881.      gotoxy(76,1);
  882.      write(x);
  883.      gotoxy(59,1);
  884.      write('        ');
  885.      gotoxy(59,1);
  886.      write(z);
  887.      window(1,3,80,24);
  888.      gotoxy(x,y);
  889.      if x=1 then
  890.        begin
  891.          u:=80;
  892.          if z=maxline then t:=z else t:=z-1;
  893.        end
  894.      else
  895.        begin
  896.          u:=x-1;
  897.          t:=z;
  898.        end;
  899.      Worksheet[t]^[u]:=ch;
  900.      if ((ch<>' ') and (z > wcnoli)) then wcnoli:=z;
  901.      if ((u > length(worksheet[t]^)) and (ch <> ' ')) then  worksheet[t]^[0]:=chr(u);
  902.    end;
  903.  
  904.   IST:
  905.  
  906.     begin
  907.       wcActive:=true;
  908.       if x < 80 then
  909.         begin
  910.           if x > length(worksheet[z]^) then
  911.             begin
  912.               write(ch);
  913.               worksheet[z]^[x]:=ch;
  914.               if ch <> ' ' then
  915.                 begin
  916.                   worksheet[z]^[0]:=chr(x);
  917.                   if z > wcnoli then wcnoli:=z;
  918.                 end;
  919.               x:=x+1;
  920.               window(1,1,80,25);
  921.               gotoxy(76,1);
  922.               write('  ');
  923.               gotoxy(76,1);
  924.               write(x);
  925.               window(1,3,80,24);
  926.               gotoxy(x,y);
  927.             end
  928.           else
  929.             begin
  930.               insert(ch,worksheet[z]^,x);
  931.               x:=x+1;
  932.               refresh(z-y+1);
  933.               gotoxy(x,y);
  934.             end;
  935.         end
  936.       else if ((wcnoli < maxline) and (z < maxline)) then       (* x=80 *)
  937.         begin
  938.            write(ch);
  939.            worksheet[z]^[80]:=ch;
  940.            worksheet[z]^[0]:=chr(80);
  941.            j:=0;
  942.            repeat
  943.            j:=j+1;
  944.            until ((worksheet[z]^[j] <> ' ') or (j=80));
  945.            aiv:=j;
  946.            x:=aiv;    z:=z+1;
  947.            if wherey < 22 then y:=y+1;
  948.            for k:=wcnoli downto z do
  949.              begin
  950.                worksheet[k+1]^:=blankString;
  951.                worksheet[k+1]^:=worksheet[k]^;
  952.              end;
  953.            worksheet[z]^:=blankString;
  954.            worksheet[z]^[0]:=chr(0);
  955.            wcnoli:=wcnoli+1;
  956.            refresh(z-y+1);
  957.            gotoxy(x,y);
  958.         end;              (* else if wcnoli < maxline then   ( x = 80 ) *)
  959.     end;     (* of the insert section *)
  960.   end;       (* of the CASE edmode of.... *)
  961.  
  962.  
  963.   UNTIL ord(ch)=27;
  964.  
  965. end;  (* of procedure edit *)
  966.  
  967.  
  968.  
  969.  PROCEDURE MainMenu;
  970.   const
  971.     tab=30;
  972.   var
  973.     MainChoice,exitChoice:char;
  974.   begin
  975.     MainChoice:='1';
  976.     REPEAT
  977.     window(1,1,80,25);
  978.     changeCursor(1);
  979.     Clrscr;
  980.     gotoxy(tab-7,1);
  981.     writeln('<<<<<<<   MAIN MENU   >>>>>>>');
  982.     gotoxy(tab,6);
  983.     write('1'); lowvideo; write(') Edit/Create'); Normvideo;
  984.     gotoxy(tab,8);
  985.     write('2'); lowvideo; write(') Load file'); Normvideo;
  986.     gotoxy(tab,10);
  987.     write('3'); lowvideo; write(') Save working copy'); Normvideo;
  988.     gotoxy(tab,12);
  989.     write('4'); lowvideo; write(') Print working copy'); NormVideo;
  990.     gotoxy(tab,14);
  991.     write('5'); lowvideo; write(') Erase working copy'); normvideo;
  992.     gotoxy(tab,16);
  993.     write('6'); lowvideo; write(') Exit');
  994.     if firstime then begin
  995.     gotoxy(1,25); write('(c) EASY-WRITE             ( program by Guy Lachance )');
  996.     end;
  997.     gotoxy(tab,20);
  998.     write('Enter choice ('); normvideo; write('1-6'); lowvideo; write(') : ');
  999.     normvideo;
  1000.     readln(MainChoice);
  1001.     if ((Mainchoice >= '1') and (Mainchoice <= '6')) then
  1002.       begin
  1003.       firstime:=false;
  1004.       case Mainchoice of
  1005.          '1':edit;
  1006.          '2':load;
  1007.          '3':save;
  1008.          '4':print;
  1009.          '5':erase;
  1010.          '6':if ((wcActive) and (wcnoli <> 0)) then
  1011.              begin
  1012.                clrscr;
  1013.                gotoxy(5,5);
  1014.                write('WARNING !!  Your changes have not been saved !');
  1015.                lowvideo;
  1016.                gotoxy(38,25);
  1017.                write('EXIT');
  1018.                normvideo;
  1019.                gotoxy(5,7);
  1020.                exitChoice:='n';
  1021.                write('Do you want to continue ?  (y/n) : ');
  1022.                read(exitChoice);
  1023.                if (not(exitChoice in ['y','Y'])) then MainChoice:='1';
  1024.              end;
  1025.        end;
  1026.       end;
  1027.     UNTIL MainChoice='6';
  1028.   end;  (* of the procedure MainMenu *)
  1029.  
  1030.  
  1031.  
  1032.  
  1033. BEGIN   (* main program *)
  1034.  
  1035.   firstime:=true;
  1036.   edmode:=ist;
  1037.   getVideoMode;
  1038.   clrscr;
  1039.   gotoxy(25,12);
  1040.   write(' One moment please... ');
  1041.   blankString:='';
  1042.   for bkstrindex:=1 to 80 do
  1043.     blankString:=blankString+' ';
  1044.   initialize;
  1045.   mainmenu;         (* go for it ! start the program ! *)
  1046.   clrscr;
  1047.  
  1048. END.    (* main program *)